import pymysql
import uuid
import datetime
import hashlib
import json
def get_db_connection(data):
    connection = pymysql.connect(
        host=data.get("host"),
        user=data.get("user"),
        password=data.get("password"),
        database=data.get("database"),
        cursorclass=pymysql.cursors.DictCursor,
        autocommit=True
    )
    return connection

def getUuid():
    return uuid.uuid4()

def md5_salted(string):
    salt = "random_salt_value"
    # 将原始字符串和盐值拼接
    string_with_salt = (string + salt).encode('utf - 8')
    md5 = hashlib.md5()
    md5.update(string_with_salt)
    return md5.hexdigest()

def getFormatted_datetime_now():
    now = datetime.datetime.now()
    formatted_datetime = now.strftime('%Y-%m-%d %H:%M:%S')
    return formatted_datetime

